perl conditional statements

149

perl conditional statements -

# Basic syntax:
if (condition_1) {  
	print "condition_1 was met\n";  
}  
elsif (condition_2) {  
	print "condition_2 was met\n";  
}  
else {
	print "for everything else, there's Mastercard\n";
}
# Note, some people like to shorten the syntax like this:
if (condition_1) {  
	print "condition_1 was met\n";  
} elsif (condition_2) {  
	print "condition_2 was met\n";  
} else { print "for everything else, there's Mastercard\n";}

# Example usage:
my $variable = 3;
if ($variable > 5) {  
	print "Three is greater than 5\n";  
}  
elsif ($variable < -7) {  
	print "Three is less than negative 7\n";  
}  
else {
	print "Apparently 3 falls between -7 and 5\n";
}

Comments

Submit
0 Comments